import os
import json
import shutil

CONFIG_PATH = os.path.expanduser("~/.video-downloader/config.json")

def load_config():
    if not os.path.exists(CONFIG_PATH):
        return {
            "download_speed_limit": 0,
            "proxy_url": "",
            "verify_ssl": True,
            "download_path": os.path.expanduser("~/Downloads"),
            "enable_auto_transcode": False,
            "transcode_format": "mp4",
            "enable_auto_subtitle": False,
            "subtitle_lang": "en",
            "embed_subtitle": False,
            "subtitle_font": "Arial",
            "font_size": 24,
            "font_color": "#FFFFFF",
            "tags": ["视频", "音频", "文档", "图片", "其他"],
            "retry_attempts": 3,
            "auto_retry_on_failure": True,
            "enable_fingerprint_dedup": False
        }
    with open(CONFIG_PATH, "r", encoding="utf-8") as f:
        return json.load(f)

def save_config(config):
    os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
    with open(CONFIG_PATH, "w", encoding="utf-8") as f:
        json.dump(config, f, ensure_ascii=False, indent=4)